"""
MonoNeurona 2008
GPLv3

Coatl -- CMS
"""
import Image
import os
from django.core.files.base import ContentFile
from django.db.models.fields.files import ImageFieldFile
from django.contrib import admin
from django import forms
from coatl.news.models import News, Category
admin.autodiscover()

class NewsAdmin(admin.ModelAdmin):
  search_fields = ('title', 'post')
  list_filter   = ('author', 'date')
  list_display  = ('author', 'date', 'title')  

  def was_published_today(self):
      return self.pub_date.date() == datetime.date.today()
      #was_published_today.short_description = 'Published today?'

  def save_model(self, request, obj, form, change):
      obj.author_id = request.user.id
      obj.save()
    
  
class CategoryAdmin(admin.ModelAdmin):
   search_fields = ('category', 'description')
   def save_model(self, request, obj, form, change):
      #obj.author_id = request.user.id
      if field.name == 'image':
             field.upload_to = 'img'
             # imagename
             #image  = 'photos/%d' % request.user.id
      obj.save()

   def save(self):
       if field.name == 'image':
             field.upload_to = 'photos/%d' % self.id
    
admin.site.register(Category)
admin.site.register(News, NewsAdmin)
